package com.econ.powercloud.ems.observer.strategy.impl;

import com.econ.powercloud.common.base.facade.util.JacksonUtil;
import com.econ.powercloud.ems.dal.entity.EmsYkYtRecord;
import com.econ.powercloud.ems.observer.strategy.YcYxAbstractStrategy;
import com.econ.powercloud.ems.service.dao.EmsYkYtRecordDAO;
import com.google.common.collect.Lists;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.List;

/**
 * yx故障告警下发值置0策略
 *
 * @author hcx
 * @since 2023/6/28 14:08
 **/
@Component
public class YxAlarmFaultStrategy extends YcYxAbstractStrategy {

    @Autowired
    EmsYkYtRecordDAO emsYkYtRecordDAO;

    public YxAlarmFaultStrategy(){
        //从数据库得知类型
        this.setType(1);
    }

    @Override
    public void strategy(List<String> data) {
        if (data.size()==0){
            return;
        }
        List<EmsYkYtRecord> updateList = Lists.newArrayList();
        //转为EmsYkYtRecord数据类型
        data.stream().forEach(d->{
            EmsYkYtRecord record = JacksonUtil.parseObject(d,EmsYkYtRecord.class);
            updateList.add(record);
        });
        //批量更新下发值为0
        emsYkYtRecordDAO.updateBatchByDitAndDeviceCode(updateList);
    }
}
